// Copyright @ ChenChao

#pragma once

#include "CoreMinimal.h"
#include "EnhancedInputComponent.h"
#include "DataAssets/Input/WarriorDataAssetInputConfig.h"
#include "WarriorInputComponent.generated.h"

/**
 * 
 */
UCLASS()
class WARRIOR_API UWarriorInputComponent : public UEnhancedInputComponent
{
	GENERATED_BODY()

public:
	//模板函数: 绑定回调函数
	template<class UserObject, typename CallbackFunc>
	void BindNativeInputAction(const UWarriorDataAssetInputConfig* InInputConfig, const FGameplayTag& InInputTag,
		ETriggerEvent TriggerEvent, UserObject* ContextObject, CallbackFunc Func);
	
};

//模板函数: 绑定回调函数
template <class UserObject, typename CallbackFunc>
void UWarriorInputComponent::BindNativeInputAction(const UWarriorDataAssetInputConfig* InInputConfig,
	const FGameplayTag& InInputTag, ETriggerEvent TriggerEvent, UserObject* ContextObject, CallbackFunc Func)
{
	//检查指针
	checkf(InInputConfig,TEXT("InInputConfig 为空指针，无法继续执行绑定操作！"));
	//通过标签查到输入动作
	UInputAction* InputAction = InInputConfig->GetNativeInputActionsByTag(InInputTag);
	//检查输入动作是否有效
	if (InputAction == nullptr) return;
	//绑定函数
	BindAction(InputAction, TriggerEvent, ContextObject, Func);
	
}
